<template>
	<view class="page">
		<!-- content -->
		<div style="z-index: 99;padding-top: 138px;position: absolute;left: 0;top: 0;right: 0;">
			<image src="../../static/mainbg.png" mode=""
				style="position: absolute;left: 0;top: 0;width: 100%;height: 110%;"></image>

			<!-- des -->
			<div style="margin: 0 30px;position: relative;height: 350px;">
				<image src="../../static/index-top-card.png"
					style="position: absolute;left: 0;top: 0;width: 100%;height: 350px;" mode=""></image>

				<!-- buy info -->
				<div style=" padding: 12px;position: absolute;left: 0;bottom: 0;right: 0;">
					<!-- row -->
					<div style="display: flex;justify-content: center;">
						<div style="display: flex;align-items: center;flex: 1;justify-content: center;margin-top: 5px;">
							<div>原价</div>
							<div style="text-decoration:line-through;margin-left: 5px;margin-top: 5px;">¥{{info.price}}</div>
						</div>
						<div style="display: flex;align-items: center;flex: 1;justify-content: center;margin-top: 5px;">
							<div>活动价</div>
							<div style="color: #ff7A3F;font-weight: bold;margin-left: 5px;margin-top: 5px;">￥{{info.activityPrice}}</div>
						</div>
					</div>
					<!-- row -->
					<div style="display: flex;justify-content: center;align-items: center;margin-top: 5px;">
						<div style="font-size: 16px;font-weight: bold;color: #ff7A3F;">仅剩</div>
						<div style="font-size: 16px;font-weight: bold;color: #ff7A3F;">{{info.surplusQuantity}}</div>
						<div style="font-size: 16px;font-weight: bold;color: #ff7A3F;">套</div>
					</div>
					<!-- row -->
					<div style="display: flex;justify-content: center;margin-top: 12px;">
						<div @click="buybtnclick"
							style="display: flex;justify-content: center;background-color: #ff0000;padding: 5px 40px;">
							<div style="font-size: 16px;font-weight: bold;color: #FFFFFF;">立即购买</div>
						</div>
					</div>
				</div>
			</div>

			<div
				style="padding: 5px 0;margin-left:31.5px;margin-right: 32.6px;border-bottom: dashed 1px #333333;background-color: #FFFFFF;">
			</div>
			<!-- bottom des -->
			<div style="margin: 0 30px;position: relative;height: 240px;overflow: hidden;background-color: #007AFF;">
				<image src="../../static/index-bottom-card.png" mode="" style="width: 100%;height: 100%;">
				</image>
				<div style="position: absolute;left: 0;bottom: 0;right: 0;display: flex;justify-content: center;">
					<image src="../../static/bottom-tip.png" mode="" style="width: 90px;height: 90px;"></image>
				</div>
				<div
					style="position: absolute;left: 0;top: 0;right: 0;bottom: 0;display: flex;flex-direction: column;align-items: center;padding: 12px 20px;font-size: 16px;">
					<div style="font-size: 14px;">活动期间</div>
					<div style="font-size: 14px;">秒杀成功即可以超低价</div>
					<div style="font-size: 14px;">
						<span style="color: #ff7A3F;font-weight: bold;">任选</span>
						一门
						<span style="font-weight: bold;">winter/spring/summer</span>学分课程
					</div>
					<div style="font-size: 14px;">（仅部分课程不适用）</div>
					<div style="font-size: 14px;">限额<span style="color: #ff7A3F;font-size: 20px;">{{info.quantity}}</span>个 </div>
					<div style="font-size: 14px;">先到先得 手速要快</div>
				</div>
			</div>
		</div>
	</view>
</template>

<script>
	import api from "../../request.js"
	export default {
		data() {
			return {
				title: 'Hello',
				info:{
					activityPrice:0,
					quantity:0,
					price:"0",
					surplusQuantity:0,
					
				},
			}
		},
		onLoad() {

		},
		mounted() {
			this.netFetchGoodsInfo()
		},

		methods: {
			netFetchGoodsInfo() {
				let self = this;
				let kdata = {}
				api({
					url: "/api/admin/seckill/order/getCommodity",
					method: 'post',
					data: kdata
				}).then(res => {
					let {data} = res;
					self.info = data;
				}).catch(e=>{
					uni.showToast({
						title:e
					})
				});
			},
			netCreateOrder(){
				let data = {
					commoditId:	this.info.commoditId,
					orderAmount:this.info.activityPrice,
					payType:1
				}
				api({
					url:"/api/admin/seckill/order/addOrder",
					method:"post",
					data
				}).then(res=>{
					let {code,msg,data} = res;
					if(code == 500) {
						uni.showModal({
							title: "很遗憾",
							content: msg,
							showCancel: false,
							confirmText: "好的"
						})
					} else {
						uni.navigateTo({
							url:"../orderinfo/orderinfo?data="+encodeURIComponent(JSON.stringify(data))
						})
					}
				}).catch(e=>{
					uni.showToast({
						title:e
					})
				})
			},
			buybtnclick() {
				this.netCreateOrder();
			}
		}
	}
</script>

<style scoped>
	.page {
		flex: 1;
		position: relative;
	}
</style>
